package edu.unh.sustain;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class FoursquareActivity extends Activity {
    WebView fsWebView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.foursquare_main);

        fsWebView = (WebView) findViewById(R.id.fs_webview);
        fsWebView.getSettings().setJavaScriptEnabled(true);
        fsWebView.loadUrl(Constants.FOURSQUARE_LINK);
        fsWebView.setWebViewClient(new WebViewClient() {
            /**
             * loads URLs within the app, instead of the native browser
             */
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return false;
            }
        });
    }

    /**
     * Handles the back button in the webview. If it can go back to a previous
     * page, it does. If not, it will return to the Transportation menu.
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (fsWebView.canGoBack() == true) {
                        fsWebView.goBack();
                    } else {
                        finish();
                    }
                    return true;
            }
        }

        return super.onKeyDown(keyCode, event);
    }
}
